package com.boot.persistence.controller.association;

import com.boot.persistence.model.BaseModel;
import com.boot.web.http.HttpModel;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.constraints.NotEmpty;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description 多对多关联查询控制层对内接口
 * @date 2019/11/13 15:42
 **/
@Validated(Default.class)
public interface IAssociationMapping<Mid extends Serializable, Nid extends Serializable,
        M extends BaseModel<Mid>, N extends BaseModel<Nid>> extends IAssociationController<Mid, Nid, M, N> {

    @Override
    @GetMapping("/mid/{mid}")
    @ApiOperation(value = "通过mid查找多条n记录")
    @ApiImplicitParam(name = "mid", value = "mid", required = true, paramType = "path", dataTypeClass = Serializable.class)
    ResponseEntity<HttpModel<Collection<N>>> m2n(@PathVariable Mid mid);

    @Override
    @PostMapping("/list/mid")
    @ApiOperation(value = "通过mid列表查找多条n记录")
    @ApiImplicitParam(name = "mids", value = "mid列表", required = true, paramType = "body", dataTypeClass = List.class)
    ResponseEntity<HttpModel<Collection<N>>> m2n(@RequestBody @NotEmpty List<Mid> mids);

    @Override
    @GetMapping("/nid/{nid}")
    @ApiOperation(value = "通过nid查找多条m记录")
    @ApiImplicitParam(name = "nid", value = "nid", required = true, paramType = "path", dataTypeClass = Serializable.class)
    ResponseEntity<HttpModel<Collection<M>>> n2m(@PathVariable Nid nid);

    @Override
    @PostMapping("/list/nid")
    @ApiOperation(value = "通过nid列表查找多条m记录")
    @ApiImplicitParam(name = "nids", value = "nid列表", required = true, paramType = "body", dataTypeClass = List.class)
    ResponseEntity<HttpModel<Collection<M>>> n2m(@RequestBody @NotEmpty List<Nid> nids);
}
